from functools import wraps

# 定义装饰器
def Tool(func):
    @wraps(func)
    def wrapper(self, *args, **kwargs):
        return func(self, *args, **kwargs)
    wrapper.is_tool = True  # 添加一个标识属性
    return wrapper

class MyClass:
    def method1(self):
        pass

    @Tool
    def method2(self):
        print("method2")

    def method3(self):
        pass

    @Tool
    def method4(self):
        print("method4")

# 创建类的实例
instance = MyClass()

# 创建一个字典来保存被装饰的方法
decorated_methods = {
    method_name: getattr(instance, method_name)
    for method_name in dir(instance)
    if callable(getattr(instance, method_name)) and getattr(getattr(instance, method_name), 'is_tool', False)
}

# 打印结果
for method_name, method in decorated_methods.items():
    print(f"{method_name} is decorated with @Tool")
    method()  # 直接调用方法